<script setup lang="ts">
import { defineEmits } from 'vue';
import type { PropType } from 'vue'

defineOptions({ name: 'Query' });

interface ModelValueType {
  courseId: any;
  mode: any;
  organizationId: any;
  name: any;
}

defineProps({
  modelValue: {
    type: Object as PropType<ModelValueType>,
    required: true
  },
  courseList: {
    type: Array,
    required: true
  },
  orgTree: {
    type: Array,
    required: true
  }
});


const search = () => {
  emit('queryData')
}

const reset = () => {
  emit('reset')
}

const emit = defineEmits(['update:modelValue', 'queryData', 'reset']);

</script>
<template>
  <section>
    <el-form :inline="true" label-width="70px" class="w-full border-b border-color:#DCDFE6 after:content-[''] mb-[15px] after:clear-both after:block">
      <el-form-item :label="$t('exam.examCourseLabel')">
        <el-select style="width: 100%" class="flex-auto" v-model="modelValue.courseId" clearable
          :placeholder="$t('common.selectPhTxt', [$t('exam.examCourseLabel')])">
          <el-option v-for="item in courseList as any" :key="item.id" :label="item.name" :value="item.id" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('exam.examTypeLabel')">
        <el-select style="width: 100%" class="flex-auto" v-model="modelValue.mode" clearable
          :placeholder="$t('common.selectPhTxt', [$t('exam.examTypeLabel')])">
          <el-option
            v-for="item in [{ label: $t('exam.online'), value: 'online' }, { label: $t('exam.offline'), value: 'offline' }] as any"
            :key="item.value" :label="item.label" :value="item.value" />
        </el-select>
      </el-form-item>
      <el-form-item :label="$t('exam.examClassLabel')">
        <el-cascader clearable :show-all-levels="false" class="w-full" v-model="modelValue.organizationId"
          :placeholder="$t('common.selectPhTxt', [$t('exam.examClassLabel')])" :options="orgTree"
          :props="{ emitPath: false, checkStrictly: true, multiple: false, label: 'name', value: 'orgId', children: 'children' }" />
      </el-form-item>
      <el-form-item label="">
        <el-input style="width: 100%" :maxlength="50" v-model="modelValue.name" clearable
          :placeholder="$t('common.inputPhTxt', [$t('exam.examNameLabel')])">
        </el-input>
      </el-form-item>
      <el-form-item label="" class="float-right">
        <div class="w-full flex justify-end">
          <el-button @click="reset">
            {{ $t('common.resetTxt') }}
          </el-button>
          <el-button type="primary" @click="search">
            {{ $t('common.searchTxt') }}
          </el-button>
        </div>
      </el-form-item>
    </el-form>
  </section>
</template>
<style lang="scss" scoped>
:deep(.el-form--inline .el-form-item) {
  margin-right: 24px;
  width: calc((100% - 72px)/4);

  &:nth-of-type(4n),
  &:last-of-type {
    margin-right: 0px;
  }
}

:deep(.el-form-item__label) {
  padding-right: 12px;
}
</style>
